package com.share.device.controller;

import com.share.common.core.web.domain.AjaxResult;
import com.share.common.security.annotation.RequiresPermissions;
import com.share.device.domain.Area;
import com.share.device.domain.dto.AreaDto;
import com.share.device.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/area")
public class AreaController {
    @Autowired
    private AreaService areaService;
    //获取区域列表
    @RequiresPermissions("device:area:getAreaList")
    @GetMapping("/getAreaList")
    public AjaxResult getAreaList(AreaDto areaDto){
        return AjaxResult.success(areaService.getAreaList(areaDto));
    }

    //添加区域
    @RequiresPermissions("device:area:add")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Area area){
        return AjaxResult.success(areaService.add(area));
    }
    @RequiresPermissions("device:area:query")
    //区域详情
    @GetMapping("/{id}")
    public AjaxResult query(@PathVariable Integer id){
        return AjaxResult.success(areaService.getAreaById(id));
    }

    //区域详情列表
    @GetMapping("/queryList/{id}")
    public AjaxResult queryList(@PathVariable Integer id){
        return AjaxResult.success(areaService.queryList(id));
    }

    //修改区域
    @PutMapping("/updArea")
    public AjaxResult updateArea(@RequestBody Area area){
        return AjaxResult.success(areaService.updateById(area));
    }

    //删除区域
    @RequiresPermissions("device:area:remove")
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Integer id){
        return AjaxResult.success(areaService.removeById(id));
    }


}
